#!/usr/bin/env python
#coding=utf-8
from google.appengine.api import memcache
import yaml
import os

class Config(object): # subclassing from object for 2.2, unnecessary after that
  instance = None
  @staticmethod
  def get_instance():
    data = memcache.get("conf" + __file__)
    if data is not None:
        return data
    else:
        data = Config.load()
        memcache.add("conf" + __file__, data, 864000)
        return data
  
  @staticmethod
  def load():
    """parses the config.yaml file"""
    _BASE_PATH = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
    config_file = os.path.join(_BASE_PATH, "conf", "app-sso.yaml")
    fh = open(config_file, "r")
    try:
      return yaml.load(fh)
    finally:
      fh.close()

if __name__ == '__main__':

    print 'qq'
    print Config.get_instance()
